export default app => {
  const { $env } = app
  console.log($env, 'env')
  console.log(app.$env, 'proxy')
  console.log(uni.$zz, '$zz')
  uni.$zz.http.setConfig(config => {
    console.log(config, 'config');
    
    config.baseURL = $env.BASE_URL /* 根域名 */
    return config
  })
  
  uni.$zz.http.interceptors.request.use(
    config => {
      const proxy = config?.custom?.proxy
      if (proxy) {
        config.baseURL = $env[proxy]
      }
      return config
    },
    config => Promise.reject(config)
  )

  uni.$zz.http.interceptors.response.use(
    response => {
      const { data } = response
      // 自定义参数
      const custom = response.config?.custom
      if (data.code !== 200) {
        if (custom.toast !== false) {
          uni.$u.toast(data.message)
        }
        if (custom?.catch) {
          return Promise.reject(data)
        }
        return new Promise(() => {})
      }
      return data.data || {}
    },
    response => Promise.reject(response)
  )
}
